<template>
	<view class="created-album">
		<uni-popup ref="createAlbum" type="center" :maskClick="false" :animation="false">
			<view class="dialog-area ac">
				<view class="fs34 title fwb">{{title}}</view>
				<input type="text" v-model="inputVal" maxlength="10" class="input-val mx-auto mb39" :placeholder="content">
				<view :class="['fs34 confirm-btn-color red mb36 confirm-text',{active:isActive}]" @click="confirm">{{confirmText}}</view>
				<view class="fs34 name-color cancel-text" @click="cancel">{{cancelText}}</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import uniPopup from '@/components/uni-popup/uni-popup.vue'
	export default {
		data() {
			return {
				inputVal:'',
				isActive:false,
			}
		},
		watch:{
			inputVal(newVal,oldVal){
				// if(!this.$common._empty(newVal)){
				// 	this.isActive = true;
				// }else{
				// 	this.isActive = false;
				// }
				
				this.isActive = newVal ? true : false;
			},
		},
		props: {
			title:{
				type:[String],
				default:'创建新相册'
			},
			content:{
				type:[String],
				default:'创建新相册名称(10字以内)'
			},
			cancelText:{
				type:[String],
				default:'取消'
			},
			confirmText:{
				type:[String],
				default:'确认创建'
			},
		},
		computed: {

		},
		components: {
			uniPopup
		},
		created() {
			
		},
		mounted() {
			// this.$refs.createAlbum.open();
		},
		methods: {
			open(){
				this.$refs.createAlbum.open();
			},
			close(){
				this.$refs.createAlbum.close();
			},
			cancel(){
				this.$emit('cancel');
				this.close();
			},
			confirm(){
				if(!this.inputVal){
					uni.showToast({
						icon: 'none',
						title: '请填写相册名称',
						duration: 2000
					});
					return;
				} 
				
				//以下操作在请求中的success中完成
				this.$emit('confirm');
				this.close();
				setTimeout(()=>{
					this.inputVal = '';
				},500)
				
			}
		}
	}
</script>

<style lang="scss">
	.dialog-area{
		padding-bottom: 36rpx;
		width: 554rpx;
		background-color: #F7F7F7;
		border-radius: 16rpx;
		padding-top:48rpx;
		.btn-group{
			height:90rpx;
			border-top:1rpx solid #F7F7F7;
			width: 100%;
			position: absolute;
			bottom:0;left:0;
			view{
				height:100%;
				line-height: 90rpx;
				&:first-child{
					border-right:1rpx solid #F7F7F7;
				}
			}
			
		}
		.title{
			margin-bottom:30rpx;
		}
		.content{
			padding:0 49rpx;
		}
		
		.input-val{
			width: 487rpx;
			height: 87rpx!important;
			background: #FFFFFF;
			border-radius: 16rpx;
		}
	}
	
	.confirm-text{
		width: 440rpx;
		height: 84rpx;
		line-height: 84rpx;
		text-align: center;
		background: #EAEAEA;
		border-radius: 42rpx;
		color:#8C8C8C;
		margin: 0 auto;
	}
	
	.active{
		background: linear-gradient(84deg, #FF7A48, #FF4C65);
		color:#fff;
	}
</style>
